package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.captainbank.tcl.tclapplication.utils.MyToast;
import com.captainbank.tcl.tclapplication.utils.StringUtil;

import butterknife.BindView;
import butterknife.OnClick;
import cn.magicwindow.mlink.annotation.MLinkRouter;

/**
 * Created by TCL on 2019/4/24.
 * Describe:
 */
@MLinkRouter(keys = {"tcl_show"})
public class JGMagicWindowActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.et_input)
    EditText etInput;
    @BindView(R.id.tv_link)
    TextView tvLink;
    @BindView(R.id.tv_show)
    TextView tvShow;
    @BindView(R.id.btn_copy)
    Button btnCopy;

    private String PARA_NAME = "paramName";
    private String paramValue;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_jg_magic_window;
    }

    @Override
    protected void initData() {
        System.out.println("输出：1");
        Bundle bundle = getIntent().getExtras();
        if(bundle!=null){
            System.out.println("输出：2");
            paramValue = bundle.getString(PARA_NAME,"");
        }
        System.out.println("输出：3" + paramValue);
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_jg_mw));
        if(StringUtil.checkIsNotNull(paramValue)){
            tvShow.setText("传入参数值：" + paramValue);
        }else{
            tvShow.setText("无参数传入");
        }
    }

    @Override
    protected void setListener() {
        btnCopy.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                etInput.setText("");
                tvLink.setText("");
                tvShow.setText("");
                return true;
            }
        });
    }

    @OnClick(R.id.btn_copy)
    public void onViewClicked() {
        String paramValue = etInput.getText().toString().trim();
        if(StringUtil.checkIsNotNull(paramValue)){
            String link = "https://acjk2n.mlinks.cc/ABmb" + "?" + PARA_NAME + "=" + paramValue;
            tvLink.setText(link);
            ClipboardManager cbm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("tcl_link",link);
            if(cbm!=null){
                cbm.setPrimaryClip(clipData);
                MyToast.toastSuccess(JGMagicWindowActivity.this, "已复制到粘贴板",false);
            }
        }else{
            MyToast.toastError(JGMagicWindowActivity.this, "请输入参数值",false);
        }

    }
}
